//////////////////////////////////////////////////////////////////////////

#ifndef _SURFACE_H_
#include "surface.h"
#endif

//////////////////////////////////////////////////////////////////////////

#ifndef _THEME_H_
#include "theme.h"
#endif

#include <SDL\SDL.h>

//#ifndef _SDL_gfxBlitFunc_h
//#include "SDL_gfxBlitFunc.h"
//#endif


void GUI_Surface::Blt(SDL_Surface *_dest, float _x, float _y, char _allign, float _horisontalMargin, float _verticalMargin)
{
    int xs = -1, ys = -1;

    if (_allign & AllignLeft) 
        xs =  0;
    else
        if (_allign & AllignRight) 
            xs =  -2;

    if (_allign & AllignTop) 
        ys = 0;
    else
        if (_allign & AllignBottom) 
            ys =  -2;

    if (m_Surface)
    {
        SDL_Rect rect;
        rect.x = (_x + _horisontalMargin) * GUI_Theme::GetResizeFactor() + xs * m_Surface->w / 2;
        rect.y = (_y  + _verticalMargin) * GUI_Theme::GetResizeFactor() / 1.6 + ys * m_Surface->h / 2;
        
        if(m_Surface) 
        {
            SDL_BlitSurface(m_Surface, NULL, _dest, &rect);
        }
    }
}

//////////////////////////////////////////////////////////////////////////


void GUI_Surface::Blt(SDL_Surface *_dest, float _x, float _y)
{
    Blt(_dest, _x, _y, AllignMiddle | AllignCenter, 0, 0);
}


//////////////////////////////////////////////////////////////////////////


float GUI_Surface::Width()
{
    if (m_Surface)
        return m_Surface->w / GUI_Theme::GetResizeFactor();
    else
        return 0;
}


//////////////////////////////////////////////////////////////////////////


float GUI_Surface::Height()
{
    if (m_Surface)
        return m_Surface->h / GUI_Theme::GetResizeFactor();
    else
        return 0;
}


//////////////////////////////////////////////////////////////////////////


GUI_Surface::~GUI_Surface()
{
    //if (m_Surface)
    //    SDL_FreeSurface(m_Surface);
}


//////////////////////////////////////////////////////////////////////////
